<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<meta charset="utf-8">
	<title>数据表列表--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<script type="text/javascript" src="/static/layui/layui.js"></script>
<!--<script type="text/javascript" src="/static/js/code/list_.js"></script>-->
<script type="text/javascript" src="/static/js/echarts/echarts.js"></script>
<script type="text/javascript" src="/static/js/jquery.1.12.1.min.js"></script>
<script type="text/javascript" src="/static/js/util/jsutil.js"></script>
<script type="text/javascript" src="/static/js/util/postUrl.js"></script>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="width: 100%;height:600px;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    var obj_bz = {};
    var obj_nf = {};
    function dataFormatter(obj,y_list,h_list) {
        //获取社区列表
        var pList = h_list;
        var temp;
        var y_start = y_list[0];
        var y_end = y_list[y_list.length-1];
        for (var year = y_start; year <= y_end; year++) {
            var max = 0;
            var sum = 0;
            temp = obj[year];
            for (var i = 0, l = temp.length; i < l; i++) {
                max = Math.max(max, temp[i]);
                sum += temp[i];
                obj[year][i] = {
                    name : pList[i],
                    value : temp[i]
                }
            }
            obj[year + 'max'] = Math.floor(max / 100) * 100;
            obj[year + 'sum'] = sum;
        }
        return obj;
    }

    HttpUtil.post(HttpUrl.baseUrl+"/chat/yearMedicalDiseases", {}, function(data){
		console.info(data);
		//机构数组
		var h_List = [];
		//疾病数组
        var b_List = [];
        //疾病饼状图数组
        var b_pie_List = [];
        //时间轴数组
		var j_List = [];
		$.each(data.data.JG,function(e,val){
            h_List.push(val.jgmc);
		});
        $.each(data.data.BZ,function(e,val){
            obj_bz[val.name]={};
            b_List.push(val.name);
            b_pie_List.push({"name":val.name,"type":'bar'});
        });
        b_pie_List.push({name: '人数占比',type: 'pie', center: ['75%', '35%'], radius: '28%', z: 100});
        $.each(data.data.NF,function(e,val){
            obj_nf[val.years]=[];
            j_List.push(val.years);
        });

        $.each(data.data.PX,function(e_1,val_1){
                //人数
                $.each(val_1,function(e_2,val_2){
                    if(obj_bz[val_2.jbmc][val_2.years] instanceof Array){

					}else{
                        obj_bz[val_2.jbmc][val_2.years] = [];
					}
                    obj_bz[val_2.jbmc][val_2.years].push(val_2.jbrs);
				});
            });
		// console.info(obj_jb);

        for(var k in obj_bz){
            obj_bz[k] = dataFormatter(obj_bz[k],j_List,h_List);
		}
		var option;
        option = {
            baseOption: {
                timeline: {
                    // y: 0,
                    axisType: 'category',
                    // realtime: false,
                    // loop: false,
                    autoPlay: true,
                    // currentIndex: 2,
                    playInterval: 1000,
                    // controlStyle: {
                    //     position: 'left'
                    // },
                    data:
						// [
                    //     '2016',
                    //     {
                    //         value: '2017',
                    //         tooltip: {
                    //             formatter: function (params) {
                    //                 return params.name + 'GDP达到又一个高度';
                    //             }
                    //         },
                    //         symbol: 'diamond',
                    //         symbolSize: 18
                    //     },
                    // ]
                    j_List,
                    label: {
                        formatter : function(s) {
                            return (new Date(s)).getFullYear();
                        }
                    }
                },
                title: {
                    subtext: '数据来自卫生局统计'
                },
                tooltip: {
                },
                legend: {
                    x: 'right',
                    //病种列表（顺序）
                    data: b_List
                },
                calculable : true,
                grid: {
                    top: 80,
                    bottom: 100,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow',
                            label: {
                                show: true,
                                formatter: function (params) {
                                    return params.value.replace('\n', '');
                                }
                            }
                        }
                    }
                },
                xAxis: [
                    {
                        'type':'category',
                        'axisLabel':{'interval':0},
                        'data':
                        //     [
                        //         '莱文医院','\n莱文医院1'
                        //     ]
                        h_List,
                        splitLine: {show: false}
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '疾病（人数）'
                    }
                ],
                series: b_pie_List
            },
            options: [
                //每年
            ]
        };
        var option_options_arr = [];
        $.each(obj_nf,function(e_1,val){
            var obj_ops = {};
            var obj_datas = [];
            $.each(obj_bz,function(e,val){
                obj_ops["title"] = {"test":e_1+"社区高发疾病人数"};
                if(obj_ops["series"] instanceof Array){

                }else{
                    obj_ops["series"] = [];
                }
                obj_ops["series"].push({"data":val[e_1]});
                obj_datas.push({"name":e,"value":val[e_1+"sum"]});
            });
            // console.info(obj_ops["series"][0]["data"]);
            obj_ops["series"].push({"data":obj_datas});
            option_options_arr.push(obj_ops);
        });
        option.options = option_options_arr;
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    },false);


</script>
</body>
</html>